home *** CD-ROM | disk | FTP | other *** search
/ Super PC 34 / Super PC 34 (Shareware).iso / spc / UTIL / DJGPP2 / V2 / DJTST200.ZIP / tests / libc / posix / utime / utime.c < prev   
Encoding:
C/C++ Source or Header  |  1995-08-27  |  893 b   |  48 lines

  1. #include <stdio.h>
  2. #include <fcntl.h>
  3. #include <unistd.h>
  4. #include <time.h>
  5. #include <unistd.h>
  6. #include <utime.h>
  7. #include <sys/stat.h>
  8.  
  9. void
  10. die(const char *m)
  11. {
  12.   printf("Error: %s\n", m);
  13.   exit(1);
  14. }
  15.  
  16. int
  17. main(void)
  18. {
  19.   time_t now;
  20.   struct stat s_before, s_after;
  21.   int fid;
  22.   struct utimbuf tb;
  23.  
  24.   time(&now);
  25.   now &= ~1; /* DOS doesn't record seconds' LSB */
  26.  
  27.   sleep(4);
  28.  
  29.   fid = open("utime.dat", O_WRONLY|O_CREAT|O_TRUNC, 0666);
  30.   if (fid < 0)
  31.     die("cannot create utime.dat");
  32.   close(fid);
  33.  
  34.   stat("utime.dat", &s_before);
  35.   printf("created file %d seconds old\n", s_before.st_mtime - now);
  36.  
  37.   tb.actime = tb.modtime = now + 100;
  38.   if (utime("utime.dat", &tb))
  39.     die("cannot set utime");
  40.  
  41.   stat("utime.dat", &s_after);
  42.   printf("utime'd file %d seconds old\n", s_after.st_mtime - now);
  43.  
  44.   remove("utime.dat");
  45.   
  46.   return 0;
  47. }
  48.